var index={
    view:function(){
        return [
            m("div.top",[
                m("div.logo",[m("span.iconfont.icon-quyu"),"系统管理"]),
                m("div.map"),
                m("div.user")
            ]),
            m("div.menu",[
                m("button.bt",[m("span.iconfont.icon-xiangmuguanli"),"系统清单"]),
                m("button.bt",[m("span.iconfont.icon-xuqiu"),"数据字典"])
            ]),
            m("div.content"),
            m("dialog"),
            m("div.print")
        ]
    }
}

index.oncreate=function(){
    document.querySelectorAll(".bt,.bt_active").forEach(bt=>{
        bt.addEventListener("click",function(){
            document.querySelectorAll(".bt,.bt_active").forEach(bt2=>{
                bt2.setAttribute("class","bt");
            })
            this.setAttribute("class","bt_active");
            index.GoPage(this)
        })
    })
    document.querySelector(".bt").click();
}
//配置
index.map={
    "系统清单":"project",
    "数据字典":"dictionary",
    "需求清单":"system_demand",
    "数据库":"database",
    "接口":"interface",
};
index.rootpath="../../";

index.GoPage=function(e){
    if(index.map[e.innerText]){
        window[index.map[e.innerText]]["Show"].call();
    }
}

index.GetPostData=function(data){
    var postData=new FormData();
    for(var i=0;i<data.length;i++){
        if(!document.querySelector("#"+data[i].key)){
            continue;
        }
        if(!data[i].regex.test(document.querySelector("#"+data[i].key).value)){
            document.querySelector("#"+data[i].key).style.backgroundColor="red";
            return false;
        }
        document.querySelector("#"+data[i].key).style.backgroundColor="white";
        postData.append(data[i].key,document.querySelector("#"+data[i].key).value);
    }
    return postData;
}

index.ShowPrint=function(title,html){
    document.body.style.overflow="auto";
    document.body.style.backgroundColor="white";
    document.querySelector(".print").style.height="auto";
    document.querySelector(".print").style.display="block";
    document.querySelector(".top").style.display="none";
    document.querySelector(".menu").style.display="none";
    document.querySelector(".content").style.display="none";
    document.querySelector(".print").innerHTML='<h1>'+title+'</h1>'+html;
}
index.HidePrint=function(){
    document.body.style.overflow="hidden";
    document.body.style.backgroundColor="#f2f2f2";
    document.querySelector(".print").style.height="100vh";
    document.querySelector(".print").style.display="none";
    document.querySelector(".top").style.display="flex";
    document.querySelector(".menu").style.display="block";
    document.querySelector(".content").style.display="block";
    document.querySelector(".print").innerHTML="";
}

m.DloadingFiles([
    "src/project.js",
    "src/dictionary.js",
    "src/system.js",
    "src/database.js",
    "src/interface.js"
],function(){
    m.render(document.body,m(index));
})